#include <iostream>
#include <algorithm>

using namespace std;

const int N = 5e4 + 10;
struct node{
	int w;
	int s;
}a[N];
int n;

bool cmp(node& x, node& y)
{
	return max(-x.s, x.w - y.s) < max(-y.s, y.w - x.s);
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i].w >> a[i].s;	
	} 
	
	sort(a + 1, a + 1 + n, cmp);
	
	int ret = -1e9, w = 0;
	for(int i = 1; i <= n; i++)
	{
		ret = max(ret, w - a[i].s);
		w += a[i].w;
	}
	
	cout << ret << endl;
	
	return 0;
}
